/*
*  Copyright (c) 2008, <Kristof Bal>, the New BSD License
* Matrixfunctions.cpp, it contains all the definations for the functions, classes,
* structures and objects  defined in matrixfunctions.h
*/
#include "matrixfunctions.h"

/*
*************************************************************
***********************Matrixoperations**********************
*************************************************************
*/

//Sum of two matrices, they should have the same dimensions
matrix matrixoperations::matrixsum(const matrix m1, const matrix m2)
{
  matrix result;
  int rowcounter=0;
  int columncounter=0;
  if (m1.i==m2.i&&m1.j==m2.j){
      result.i=m1.i;
      result.j=m1.j;
      while(rowcounter<result.i){
          while(columncounter<result.j){
              result.values[rowcounter][columncounter]=m1.values[rowcounter][columncounter]+m2.values[rowcounter][columncounter];
              columncounter++;
          }
          columncounter=0;
          rowcounter++;
      }
      return(result);
  }
  else{
      return (0);
  }
}

//Subtraction of two matrices, they should have the same dimensions.
//The operation is m1-m2
matrix matrixoperations::matrixsubtraction(const matrix m1, const matrix m2)
{
  matrix result;
  int rowcounter=0;
  int columncounter=0;
  if (m1.i==m2.i&&m1.j==m2.j){
      result.i=m1.i;
      result.j=m1.j;
      while(rowcounter<result.i){
          while(columncounter<result.j){
              result.values[rowcounter][columncounter]=m1.values[rowcounter][columncounter]-m2.values[rowcounter][columncounter];
              columncounter++;
          }
          columncounter=0;
          rowcounter++;
      }
      return(result);
  }
  else{
      return (0);
  }
}

/*
*************************************************************
***********************Matrixgeneration**********************
*************************************************************
*/

matrix matrixgeneration::identitymatrix(const unsigned int dimension)
{
    int counter=0;
    matrix result;
    result.i=dimension;
    result.j=dimension;
    while(counter<dimension){
        result.values[counter][counter]=1;
        counter++;
    }
    return(result);
}
